﻿SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON

GO


CREATE PROCEDURE [dbo].[bhp_temp_ModBlogStructure]
AS
BEGIN

	DECLARE
		@SettingsGroupId				INT,
		@DefaultSettingsTabId		INT,
		@SimilarSettingsTabId		INT
		
	SELECT @SettingsGroupId = id FROM n_Tree WHERE name = 'BLOG_SETTINGS' AND parent = 0
	
	INSERT INTO bht_GroupTabs (TabName, Sort)
		VALUES ('Podstawowe ustawienia', 100)

	SELECT @DefaultSettingsTabId = SCOPE_IDENTITY()
	
	INSERT INTO bht_GroupTabs (TabName, Sort)
		VALUES ('Ustawienia systemu podobnych postów', 200)

	SELECT @SimilarSettingsTabId = SCOPE_IDENTITY()

	UPDATE
		bht_Columns
	SET
		Sort = CASE t.name
					WHEN 'title' THEN 100
					WHEN 'subtitle' THEN 200
					WHEN 'use_tag_system' THEN 300
					WHEN 'allow_user_change_url' THEN 400
					WHEN 'enable_short_description' THEN 500
				END
	FROM
		n_Tree t
		INNER JOIN bht_Columns c ON t.id = c.ColumnId
	WHERE
		t.parent = @SettingsGroupId
		AND t.name IN ('title', 'subtitle', 'use_tag_system', 'allow_user_change_url', 'enable_short_description')
		
	INSERT INTO bht_GroupColumnsSplit (ColumnId, TabId)
		SELECT id, @DefaultSettingsTabId FROM n_Tree WHERE name IN ('title', 'subtitle', 'use_tag_system', 'allow_user_change_url', 'enable_short_description') AND parent = @SettingsGroupId

	INSERT INTO bht_GroupColumnsSplit (ColumnId, TabId)
		SELECT id, @SimilarSettingsTabId FROM n_Tree WHERE name IN ('similar_post_use_system', 'similar_post_count', 'similar_post_dayago', 'similar_post_futuredays') AND parent = @SettingsGroupId

END
GO

EXEC [bhp_temp_ModBlogStructure]
GO

DROP PROCEDURE [bhp_temp_ModBlogStructure]